#include "./../includes/cliente.h"

cliente::cliente( const int _seed )
{
	std::stringstream
	stream;
	
	stream << "cliente" << _seed;
	
	this->setName( stream.str() );
	stream.str("");
	
	this->isPutao = false;

	this->instantiantionTime = time( 0 ) - settings::getInstance()->getInitTime();

	this->settingsInstance = settings::getInstance();

	srand( _seed );
	
	int
	randomNumber = (rand() % this->settingsInstance->getTempoMaximo()) + 1;

	this->problemDuration = randomNumber ;
}

cliente::~cliente()
{

}
	
void
cliente::setName (const std::string _name)
{
	this->name = _name;
}
	
std::string
cliente::getName() const
{
	return this->name;
}
	
int
cliente::getProblemDuration()
{
	if ( this->instantiantionTime - settings::getInstance()->getInitTime() > 2 * this->problemDuration )
	{
		this->setIsPutao( true );

		return this->problemDuration * 2;
	}

	return this->problemDuration;
}

bool
cliente::getIsPutao() const
{
	return this->isPutao;
}

time_t
cliente::getInstantiationTime() const
{
	return this->instantiantionTime;
}

time_t
cliente::getTimingOnQueue()
{
	time_t
	now = time( 0 ) - settings::getInstance()->getInitTime();
	
	return now - this->instantiantionTime;
}

void
cliente::setIsPutao (const bool _isPutao )
{
		this->isPutao = _isPutao;
}
